/*   1:    */ package org.jetbrains.generate.tostring.config;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.generate.tostring.psi.PsiAdapter;

import java.util.Collections;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */ 
/*  17:    */ public class FilterPattern
/*  18:    */ {
/*  19: 38 */   private static final Logger a = Logger.getInstance("#org.jetbrains.generate.tostring.config.FilterPattern");
/*  20: 39 */   private static final Set<String> b = new THashSet();
/*  21:    */   private String c;
/*  22:    */   private String d;
/*  23:    */   private String e;
/*  24:    */   private String f;
/*  25:    */   private boolean g;
/*  26:    */   private boolean h;
/*  27:    */   private boolean i;
/*  28:    */   private boolean j;
/*  29:    */   private boolean k;
/*  30:    */   
/*  31:    */   static
/*  32:    */   {
/*  33: 41 */     Collections.addAll(b, new String[] { "org.apache.log4j.Logger", "java.util.logging.Logger", "org.apache.commons.logging.Log", "org.slf4j.Logger" });
/*  34:    */   }
/*  35:    */   
/*  36: 54 */   private Pattern l = null;
/*  37: 55 */   private Pattern m = null;
/*  38: 56 */   private Pattern n = null;
/*  39: 57 */   private Pattern o = null;
/*  40:    */   
/*  41:    */   public boolean fieldMatches(PsiField paramPsiField)
/*  42:    */   {
/*  43: 60 */     if ((isConstantField()) && (PsiAdapter.isConstantField(paramPsiField))) {
/*  44: 61 */       return true;
/*  45:    */     }
/*  46: 63 */     if ((isEnumField()) && (PsiAdapter.isEnumField(paramPsiField))) {
/*  47: 64 */       return true;
/*  48:    */     }
/*  49: 66 */     if ((isStaticModifier()) && (paramPsiField.hasModifierProperty("static"))) {
/*  50: 67 */       return true;
/*  51:    */     }
/*  52: 69 */     if ((isTransientModifier()) && (paramPsiField.hasModifierProperty("transient"))) {
/*  53: 70 */       return true;
/*  54:    */     }
/*  55: 72 */     Pattern localPattern1 = getFieldNamePattern();
/*  56: 73 */     if ((localPattern1 != null) && (localPattern1.matcher(paramPsiField.getName()).matches())) {
/*  57: 74 */       return true;
/*  58:    */     }
/*  59: 76 */     String str = paramPsiField.getType().getCanonicalText();
/*  60: 77 */     Pattern localPattern2 = getFieldTypePattern();
/*  61: 78 */     if ((localPattern2 != null) && (localPattern2.matcher(str).matches())) {
/*  62: 79 */       return true;
/*  63:    */     }
/*  64: 81 */     if ((isLoggers()) && (b.contains(str))) {
/*  65: 82 */       return true;
/*  66:    */     }
/*  67: 84 */     return false;
/*  68:    */   }
/*  69:    */   
/*  70:    */   public boolean methodMatches(@NotNull PsiMethod paramPsiMethod)
/*  71:    */   {
/*  72: 88 */     if (paramPsiMethod == null) {
/*  73: 88 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/generate/tostring/config/FilterPattern", "methodMatches" }));
/*  74:    */     }
/*  75: 88 */     String str1 = paramPsiMethod.getName();
/*  76: 89 */     Pattern localPattern1 = getMethodNamePattern();
/*  77: 90 */     if ((localPattern1 != null) && (localPattern1.matcher(str1).matches())) {
/*  78: 91 */       return true;
/*  79:    */     }
/*  80: 93 */     PsiType localPsiType = paramPsiMethod.getReturnType();
/*  81: 94 */     if (localPsiType == null) {
/*  82: 95 */       return false;
/*  83:    */     }
/*  84: 97 */     Pattern localPattern2 = getMethodTypePattern();
/*  85: 98 */     String str2 = localPsiType.getCanonicalText();
/*  86: 99 */     return (localPattern2 != null) && (this.m.matcher(str2).matches());
/*  87:    */   }
/*  88:    */   
/*  89:    */   public Pattern getFieldNamePattern()
/*  90:    */   {
/*  91:103 */     if (StringUtil.isEmpty(this.c)) {
/*  92:104 */       return null;
/*  93:    */     }
/*  94:106 */     if (this.n == null) {
/*  95:    */       try
/*  96:    */       {
/*  97:108 */         this.n = Pattern.compile(this.c);
/*  98:    */       }
/*  99:    */       catch (PatternSyntaxException localPatternSyntaxException)
/* 100:    */       {
/* 101:110 */         this.c = null;
/* 102:111 */         a.warn(localPatternSyntaxException.getMessage());
/* 103:    */       }
/* 104:    */     }
/* 105:114 */     return this.n;
/* 106:    */   }
/* 107:    */   
/* 108:    */   public void setFieldName(String paramString)
/* 109:    */   {
/* 110:123 */     this.c = paramString;
/* 111:    */   }
/* 112:    */   
/* 113:    */   public boolean isConstantField()
/* 114:    */   {
/* 115:127 */     return this.g;
/* 116:    */   }
/* 117:    */   
/* 118:    */   public void setConstantField(boolean paramBoolean)
/* 119:    */   {
/* 120:136 */     this.g = paramBoolean;
/* 121:    */   }
/* 122:    */   
/* 123:    */   public boolean isTransientModifier()
/* 124:    */   {
/* 125:140 */     return this.i;
/* 126:    */   }
/* 127:    */   
/* 128:    */   public void setTransientModifier(boolean paramBoolean)
/* 129:    */   {
/* 130:149 */     this.i = paramBoolean;
/* 131:    */   }
/* 132:    */   
/* 133:    */   public boolean isStaticModifier()
/* 134:    */   {
/* 135:153 */     return this.h;
/* 136:    */   }
/* 137:    */   
/* 138:    */   public void setStaticModifier(boolean paramBoolean)
/* 139:    */   {
/* 140:162 */     this.h = paramBoolean;
/* 141:    */   }
/* 142:    */   
/* 143:    */   public Pattern getMethodNamePattern()
/* 144:    */   {
/* 145:166 */     if (StringUtil.isEmpty(this.e)) {
/* 146:167 */       return null;
/* 147:    */     }
/* 148:169 */     if (this.l == null) {
/* 149:    */       try
/* 150:    */       {
/* 151:171 */         this.l = Pattern.compile(this.e);
/* 152:    */       }
/* 153:    */       catch (PatternSyntaxException localPatternSyntaxException)
/* 154:    */       {
/* 155:173 */         this.e = null;
/* 156:174 */         a.warn(localPatternSyntaxException.getMessage());
/* 157:    */       }
/* 158:    */     }
/* 159:177 */     return this.l;
/* 160:    */   }
/* 161:    */   
/* 162:    */   public void setMethodName(String paramString)
/* 163:    */   {
/* 164:186 */     this.e = paramString;
/* 165:    */   }
/* 166:    */   
/* 167:    */   public boolean isEnumField()
/* 168:    */   {
/* 169:190 */     return this.j;
/* 170:    */   }
/* 171:    */   
/* 172:    */   public void setEnumField(boolean paramBoolean)
/* 173:    */   {
/* 174:200 */     this.j = paramBoolean;
/* 175:    */   }
/* 176:    */   
/* 177:    */   public boolean isLoggers()
/* 178:    */   {
/* 179:204 */     return this.k;
/* 180:    */   }
/* 181:    */   
/* 182:    */   public void setLoggers(boolean paramBoolean)
/* 183:    */   {
/* 184:214 */     this.k = paramBoolean;
/* 185:    */   }
/* 186:    */   
/* 187:    */   public Pattern getFieldTypePattern()
/* 188:    */   {
/* 189:218 */     if (StringUtil.isEmpty(this.d)) {
/* 190:219 */       return null;
/* 191:    */     }
/* 192:221 */     if (this.o == null) {
/* 193:    */       try
/* 194:    */       {
/* 195:223 */         this.o = Pattern.compile(this.d);
/* 196:    */       }
/* 197:    */       catch (PatternSyntaxException localPatternSyntaxException)
/* 198:    */       {
/* 199:225 */         this.d = null;
/* 200:226 */         a.warn(localPatternSyntaxException.getMessage());
/* 201:    */       }
/* 202:    */     }
/* 203:229 */     return this.o;
/* 204:    */   }
/* 205:    */   
/* 206:    */   public void setFieldType(String paramString)
/* 207:    */   {
/* 208:239 */     this.d = paramString;
/* 209:    */   }
/* 210:    */   
/* 211:    */   public Pattern getMethodTypePattern()
/* 212:    */   {
/* 213:243 */     if (StringUtil.isEmpty(this.f)) {
/* 214:244 */       return null;
/* 215:    */     }
/* 216:246 */     if (this.m == null) {
/* 217:    */       try
/* 218:    */       {
/* 219:248 */         this.m = Pattern.compile(this.f);
/* 220:    */       }
/* 221:    */       catch (PatternSyntaxException localPatternSyntaxException)
/* 222:    */       {
/* 223:250 */         this.f = null;
/* 224:251 */         a.warn(localPatternSyntaxException.getMessage());
/* 225:    */       }
/* 226:    */     }
/* 227:254 */     return this.m;
/* 228:    */   }
/* 229:    */   
/* 230:    */   public void setMethodType(String paramString)
/* 231:    */   {
/* 232:264 */     this.f = paramString;
/* 233:    */   }
/* 234:    */   
/* 235:    */   public String toString()
/* 236:    */   {
/* 237:268 */     return "FilterPattern{fieldName='" + this.c + "'" + "fieldType='" + this.d + "'" + ", methodName='" + this.e + "'" + ", methodType='" + this.f + "'" + ", constantField=" + this.g + ", staticModifier=" + this.h + ", transientModifier=" + this.i + ", enumField=" + this.j + ", loggers=" + this.k + "}";
/* 238:    */   }
/* 239:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.generate.tostring.config.FilterPattern

 * JD-Core Version:    0.7.0.1

 */